<template>
  <div class="flex">
    <form novalidate class="form-inline">
        <div class="form-group">
          <datepicker id="startdate" placeholder="时间"
            v-model="model.f_date"
            :value.sync="model.f_date"
            :disabled-days-of-Week="[]"
            :format="'yyyy-MM-dd'">
          </datepicker>
<!--
          <input  type="time" class="form-group" v-model="model.upTime" placeholder='上班时间'
          condition="upTime like '%{}%'" :size="model.upTime ? model.upTime.length * 2 : 4"> -->
        </div>

      上班时间:
      <input type="time" class="form-group"  v-model="model.upTime">
      下班时间:
      <input type="time" class="form-group" v-model="model.downTime">

      <!-- <button type="button" class="btn btn-success width-80" @click="confirm()">查询</button> -->
      <div class="form-group">
           <button type="button" class="btn btn-success width-80" @click="confirm()">查询</button>
      </div>

      <br>
      <div class="form-group">
        部门:
        <chooser :userid.sync='loginer.id' resource-type="organization" :width='200' :select-data.sync='model.chosenOrg'></chooser>
        {{model.chosenOrg.fullname}}
      </div>
      
    </form>
    <div class="span">
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>日期</th>
            <th>员工</th>
            <th>上班签到时间</th>
            <th>上班签退时间</th>
            <th>状态</th>
          </tr>
        </template>
        <template partial='body'>
            <td>{{$index+1}}</td>
            <td>{{row.f_date}}</td>
            <td>{{row.f_user_name}}</td>
            <td>{{row.f_signin_time}}</td>
            <td>{{row.f_knockoff_time}}</td>
            <td>{{row.f_state}}</td>
        </template>
      </data-grid>
    </div>
  </div>
</template>

<script>
import co from 'co'
import * as Util from '../Util'
import AppData from '../../stores/AppData'
let search = function * (self) {
  let state = yield self.$post('rs/sql/考勤查询', {data: {org_id: self.model.chosenOrg.id, f_date: self.model.f_date}}, {resolveMsg: null, rejectMsg: null})
  self.model.rows = state.data

  for (var row of self.model.rows) {
    Util.getAttendanceState(row, self.model.upTime, self.model.downTime)
  }
}

export default {
  title: '上下班签到管理',
  data () {
    console.log('0000000000000', Util)
    console.log('0000000000000',Util.f)
    return {
      model: {
        rows: [],
        f_date: '',
        upTime: '08:00:00',
        downTime: '18:00:00',
        chosenOrg: {
          id: 0
        }
      },
      loginer: Util.f,
      f: Util.f
    }
  },
  // props: ['f'],
  methods: {
    confirm () {
      let gen = search(this)
      return co(gen)
    }
  },
  ready () {
    this.model.f_date = Util.toStandardDateString()
    this.model.chosenOrg.id = this.f.parentid
  },
  computed: {
    chosenOrgType () {
      // return [{label: '全部', value: ''}]
      return [{label: '全部', value: ''}, ...AppData.getParam('部门')]
    }
  }
}
</script>
